#include "stdafx.h"
#include <LitInputSystem.h>
#if LIT_OGRE_SUPPORT


//LIT_API Lit::InputSystem* Lit::Singleton<Lit::InputSystem>::instance_ = 0;
namespace Lit
{
	Key::Key( KeyEnum cod ): down(false), code(cod){}
	Key::Key( const Key & k ) : code(k.code), down(k.down){}
			
	bool Key::isSpecial( KeyEnum k )
	{
		return k == Key_ArrowRight ||
			k == Key_ArrowLeft ||
			k == Key_ArrowUp ||
			k == Key_ArrowDown ||
			k == Key_Backspace ||
			k == Key_Return;
	}
	bool Key::isSpecial( ) const
	{
		return Key::isSpecial( code );
	}
	InputSystem::InputSystem(){
		for( unsigned short i=0; i<256; i++ )
		{
			KeyEnum k=KeyEnum(i);
			mKeys[k] = Key(k);
			mKeys[k].down = false;
		}
	}
	InputSystem::InputSystem( const InputSystem& rk ) : mKeys( rk.mKeys ){}
	InputSystem::~InputSystem(){}
		
	bool InputSystem::isModifierDown( KeyModifier m ) const
	{
		return (GetAsyncKeyState( (int)m ) & 0x8000) != NULL;
	}
	bool InputSystem::isKeyDown( KeyEnum e ) const
	{
		KeyMap::const_iterator it = mKeys.find(e);
		if( it == mKeys.end() ) return false;
		return it->second.down;
	}
	bool InputSystem::isKeyUp( KeyEnum e ) const
	{
		return !isKeyDown(e);
	}

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
	void InputSystem::captureWindows(){
		for( unsigned short i=0; i<256; i++ )
		{
			KeyEnum k=KeyEnum(i);
			if( mKeys.find(k) == mKeys.end() )
				mKeys[k] = Key(k);
			mKeys[k].down = (GetAsyncKeyState((int)k)&0x8000) != NULL;
		}

	}
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
	void InputSystem::captureMac(){
		for( unsigned short i=0; i<256; i++ )
		{
			KeyEnum k=KeyEnum(i);
			if( mKeys.find(k) == mKeys.end() )
				mKeys[k] = Key(k);
			mKeys[k].down = (GetAsyncKeyState((int)k)&0x8000) != NULL;
		}
	}
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
	void InputSystem::captureLinux(){
		for( unsigned short i=0; i<256; i++ )
		{
			KeyEnum k=KeyEnum(i);
			if( mKeys.find(k) == mKeys.end() )
				mKeys[k] = Key(k);
			mKeys[k].down = (GetAsyncKeyState((int)k)&0x8000) != NULL;
		}
	}
#endif
};

#endif